/**
 * HelpContentFrame.java
 * 2012-3-21 下午11:01:15
 */
package xgenerator.ui.swing;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.net.URL;

import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import xgenerator.util.ResourceUtils;

/**
 * <p>
 * Title:HelpContentFrame
 * </p>
 * <p>
 * Description:具体功能见各方法描述
 * </p>
 * <p>
 * Copyright:Copyright (c) 2012
 * </p>
 * 
 * @author <a href="mailto:lishushan@gmail.com">liss</a>
 * @version 1.0
 */
public class HelpContentFrame extends JFrame implements UIConstants {
	
	/**
	 * constructor
	 */
	public HelpContentFrame() {
		initComponents();
	}
	
	/**
	 * <p>
	 * Title：初始化界面
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 */
	private void initComponents() {
		this.setTitle("帮助主题");
		this.setIconImage(IconUtils.createIconImage(APP_ICON_IMAGE));
		this.setContentPane(buildContentPane());

		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
		int screenHeight = screenSize.height;
		int screenWidth = screenSize.width;
		this.setSize(screenWidth / 2, screenHeight / 2);
		this.setLocation((screenWidth - getWidth()) / 2, (screenHeight - getHeight()) / 2);
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		this.setVisible(true);
	}
	
	private JPanel buildContentPane() {
		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
		
		panel.add(buildCenterPane(), BorderLayout.CENTER);

		return panel;
	}
	
	private JScrollPane buildCenterPane() {
		JEditorPane editorPane = null;
		try {
			editorPane = new JEditorPane();
			editorPane.setEditable(false);
			editorPane.setPage(ResourceUtils.getClasspathResource("xgenerator/help/index.html"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		JScrollPane scrollPane = new JScrollPane(editorPane);

		return scrollPane;
	}
	
}
